package com.ruoyi.contract.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.contract.domain.vo.ConBusinessDetail;

import lombok.Data;
import org.apache.ibatis.type.JdbcType;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.*;
import java.util.Date;
import java.util.List;

/**
 * 合同主对象 CON_BUSINESS
 *
 * @author ruoyi
 * @date 2021-09-08
 */
@Data

@TableName("CON_BUSINESS")
@KeySequence("SEQ_CON_BUSINESS")
public class ConBusiness extends ConBaseEntity {

        /** 合同主表id */
        @TableId(value = "CON_ID",type = IdType.INPUT)
        private Long conId;

        /** 合同代码 */
        @TableField("CON_CODE")
        private String conCode;


        /** 合同开始日期 */
        @TableField(value = "CON_START_TIME",jdbcType = JdbcType.DATE,updateStrategy = FieldStrategy.IGNORED)
        @JsonFormat(pattern = "yyyy-MM-dd")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date conStartTime;

        /** 合同结束日期 */
        @TableField(value = "CON_END_TIME",jdbcType = JdbcType.DATE,updateStrategy = FieldStrategy.IGNORED)
        @JsonFormat(pattern = "yyyy-MM-dd")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date conEndTime;

        /** 经办人 */
        @TableField("HANDLE_NAME")
        private String handleName;

        /** 是否冻结合同 */
        @TableField("IS_FROZEN")
        private String isFrozen;

        /** 是否通用合同*/
        @TableField("IS_TEMPLATE")
        private String isTemplate;

        /** 删除标志*/
        @TableField("DEL_FLAG")
        /** 删除标志（0代表存在 2代表删除） */
        @TableLogic(value = "0",delval = "2")
        private String delFlag;

        /** 删除人*/
        @TableField("DEL_NAME")
        private String delName;

        /** 删除时间*/
        @TableField("DEL_TIME")
        @JsonFormat(pattern = "yyyy-MM-dd")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date delTime;

        /** 码头*/
        @TableField("COMPANY_COD")
        private String companyCode;

        /** 码头名称*/
        @TableField("COMPANY_NAM")
        private String companyNam;

        /** 备注 */
        @TableField("REMARK")
        private String remark;

        /** 优先级 */
        @TableField("CON_PRIORITY")
        private Integer conPriority;

        @TableField(exist = false)
        private Date createTimeFormate;

        @TableField(exist = false)
        private List<ConBusinessType> conBusinessTypeList;

        @TableField(exist = false)
        private List<ConBusiness> childrenConBusiness;

        @TableField(exist = false)
        private List<String> dateRange;

        public ConBusiness(){

        }

        public ConBusiness(ConBusinessDetail conBusinessDetail){
                this.conStartTime = conBusinessDetail.getConStartTime();
                this.conEndTime = conBusinessDetail.getConEndTime();
                this.remark = conBusinessDetail.getRemark();
                this.conPriority=conBusinessDetail.getConPriority();
        }

        public static ConBusiness addinit(ConBusiness conBusiness){
                conBusiness.setIsFrozen("0");
                conBusiness.setIsTemplate("0");
                return conBusiness;
        }

        /**
         * 深拷贝
         * @return 新的ConBusiness对象
         */
        public ConBusiness deepCopyConBusiness() {
                ConBusiness business = null;
                try { // 将该对象序列化成流,因为写在流里的是对象的一个拷贝，而原对象仍然存在于JVM里面。所以利用这个特性可以实现对象的深拷贝
                        // ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(baos);
                        oos.writeObject(this);
                        // 将流序列化成对象
                        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
                        ObjectInputStream ois = new ObjectInputStream(bais);
                        business = (ConBusiness) ois.readObject();
                } catch (IOException e) {
                        e.printStackTrace();
                } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                }
                return business;
        }
}
